﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyDash : EnemyBase
{
    private bool colliderReset;

    public override void Init(EnemyMode mode, Vector3 spawnPos, FaceDir dir)
    {
        base.Init(mode, spawnPos, dir);
    }

    protected override void FixedTick(float fixedDeltaTime)
    {
        if (bIsDead)
        {
            return;
        }

        if (colliderReset)
        {
            col2d.enabled = true;
            colliderReset = false;
        }
        float x = rb2d.position.x + HorizontalSpeed * fixedDeltaTime;
        float offsetY = Mathf.Sin(Time.time * VerticalOffsetFrequency) * VerticalOffsetRange;
        float y = rb2d.position.y + offsetY;

        rb2d.MovePosition(new Vector2(x, y));

        //超出边界处理
        if (x < EnumBase.levelLeftEdge)
        {
            col2d.enabled = false;
            colliderReset = true;
            rb2d.MovePosition(spawnPos);
        }
        if (x > EnumBase.levelRightEdge)
        {
            col2d.enabled = false;
            colliderReset = true;
            rb2d.MovePosition(spawnPos);
        }
    }
}
